package LeetCode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Solution1 {
    public boolean isBalanced(TreeNode root) {
        recursion(root);
        return sign;
    }

    public boolean sign = true;
    public int recursion(TreeNode node) {
        if(node == null) {
            return 0;
        }
        int l = recursion(node.left);
        int r = recursion(node.right);
        if(l < r) {
            int temp = l;
            l = r;
            r = temp;
        }
        if(l - r > 1) {
            sign = false;
        }
        return l + 1;
    }
}
/*class Solution {
    public List<List<Integer>> levelOrder(TreeNode root) {
        List<List<Integer>> list = new ArrayList<>();
        LinkedList<TreeNode> queue = new LinkedList();
        queue.offer(root);
        while(!queue.isEmpty()) {

            List<Integer> list1 = new ArrayList<>();
            for(int i = 0; i < queue.size(); i++) {
                TreeNode poll = queue.poll();
                if(poll.left != null) {
                    queue.offer(poll.left);
                }
                if(poll.right != null) {
                    queue.offer(poll.right);
                }
                list1.add(poll.val);
            }
            list.add(list1);
        }
        return list;

  */

